package com.example.demo.controller;

import com.example.demo.entity.CourseComment;
import com.example.demo.service.CourseCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/courseComments")
@CrossOrigin
public class CourseCommentController {

    @Autowired
    private CourseCommentService courseCommentService;

    // 新增课程评论
    @PostMapping
    public int insertCourseComment(@RequestBody CourseComment courseComment) {
        return courseCommentService.insertCourseComment(courseComment);
    }

    // 删除课程评论
    @DeleteMapping("/{id}")
    public int deleteCourseCommentById(@PathVariable int id) {
        return courseCommentService.deleteCourseCommentById(id);
    }

    // 修改课程评论
    @PutMapping
    public int updateCourseComment(@RequestBody CourseComment courseComment) {
        return courseCommentService.updateCourseComment(courseComment);
    }

    // 查询课程评论
    @GetMapping("/{id}")
    public CourseComment selectCourseCommentById(@PathVariable int id) {
        return courseCommentService.selectCourseCommentById(id);
    }

    // 查询所有课程评论
    @GetMapping
    public List<CourseComment> selectAllCourseComments() {
        return courseCommentService.selectAllCourseComments();
    }

    // 联合查询课程的所有评论
    @GetMapping("/course/{courseId}")
    public List<CourseComment> selectCourseCommentsByCourseId(@PathVariable int courseId) {
        return courseCommentService.selectCourseCommentsByCourseId(courseId);
    }
}
